package cn.lizemin.entity.demo;

import cn.hutool.json.JSONUtil;
import cn.lizemin.entity.User;
import cn.lizemin.service.UserApi;
import cn.lzm.bootstrap.ConsumerBootstrap;
import cn.lzm.proxy.CommonServiceProxyFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author lzm
 * @Date 2024/7/20
 * @description
 */
public class ConsumerTestV4 {

    /**
     * 使用动态代理来rpc调用远程接口
     * <p>
     * 测试消费者的本地缓存
     */
    public static void main(String[] args) throws InterruptedException {
        // 注册中心初始化
        ConsumerBootstrap.init();

        UserApi proxy = CommonServiceProxyFactory.getProxy(UserApi.class);
        User user = proxy.getUserById(100);
        System.out.println(JSONUtil.toJsonStr(user));
        User user2 = proxy.getUserById(200);
        System.out.println(JSONUtil.toJsonStr(user2));
        TimeUnit.SECONDS.sleep(10);
        User user3 = proxy.getUserById(300);
        System.out.println(JSONUtil.toJsonStr(user3));
    }

}
